<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;
class Me extends Controller
{
    public function index()
    {
       $user_id = Session::get("user_id");
        $me = Db::table('user')
        ->where('user_id',$user_id)
       ->select();
        // dump($me);
        // exit;
        $this->assign("me",$me);
       return $this->fetch();
    }
    public function jl()
    {
        $user_id = Session::get("user_id");
        $jl = Db::table('resume')
        ->where('user_id',$user_id)
        ->where('resume_status',0)
       ->select();
    //    dump($jl);
    //    exit;
       $this->assign("jl",$jl);
       return $this->fetch();
    }
    public function jldetails($resume_id)
    {
        $user_id = Session::get("user_id");
        $jl = Db::table('resume')
        ->where('user_id',$user_id)
        ->where('resume_status',0)
        ->where('resume_id',$resume_id)
       ->select();
    //    dump($jl);
    //    exit;
       $this->assign("jl",$jl);
       return $this->fetch();
    }
    public function addjl()
    {
       return $this->fetch();
    }
    public function shou()
    {
        $user_id = Session::get("user_id");
        $jl = Db::table('collect c')
        ->join('position p','c.position_id = p.position_id')
        ->where('c.user_id',$user_id)
        ->where('position_status',0)
      ->select();
    //    dump($jl);
    //    exit;
       $this->assign("jl",$jl);
       return $this->fetch();
    }
    public function lishi()
    {
        $user_id = Session::get("user_id");
        $jl = Db::table('send c')
        ->join('position p','c.position_id = p.position_id')
        ->where('c.user_id',$user_id)
        ->where('c.send_status',0)
      ->select();
    //    dump($jl);
    //    exit;
       $this->assign("jl",$jl);
       return $this->fetch();
    }
    public function updateme()
    {
       return $this->fetch();
    }
    public function updateme1()
    {
        $file = request()->file('user_pic');
        if($file){
            $info = $file->rule('uniqid')->validate(['size' => 5242880, 'ext' => 'jpg,jpeg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'static' . DS .'uploads');
            if($info){
                 $user_pic= $info->getFilename(); 
            }else{
                // 上传失败获取错误信息
                // echo $file->getError();
            }
        }
        $user_id = Session::get("user_id");
        $data = [
            "user_phone"=>input('user_phone'),
            "user_name"=>input('user_name'),
            "user_gender"=>input('user_gender'),
            "user_pic"=>$user_pic,
            "user_email"=>input('user_email'),
            "user_site"=>input('user_site'),
            "user_school"=>input('user_school'),
            "user_major"=>input('user_major'),
        ];
        $res = Db::table('user')->where('user_id',$user_id)->update($data);
        if($res)
        {
            return $this->success('修改成功','me/index');
        }
        else
        {
            return $this->error('修改失败');
        }
    }
    public function addjl1()
    {
        $user_id = Session::get("user_id");
        $data = [
            "user_id"=>$user_id,
            "resume_title"=>input('resume_title'),
            "resume_name"=>input('resume_name'),
            "resume_school"=>input('resume_school'),
            "resume_off"=>input('resume_off'),
            "resume_phone"=>input('resume_phone'),
            "resume_email"=>input('resume_email'),
            "resume_jop"=>input('resume_jop'),
            "resume_word"=>input('resume_word'),
            "resume_pro"=>input('resume_pro'),
            "resume_honor"=>input('resume_honor'),
            "resume_status"=>0,
            "resume_time"=>date('Y-m-d H:i:s',time()),
        ];
        $res = Db::table('resume')->insert($data);
        if($res)
        {
            return $this->success('添加成功','me/jl');
        }
        else
        {
            return $this->error('添加失败');
        }
    }
    public function jldel($resume_id)
    {
        $data = [
            "resume_status"=>1,
        ];
        $res = Db::table('resume')->where('resume_id',$resume_id)->update($data);
        if($res)
        {
            return $this->success('删除成功','me/jl');
        }
        else
        {
            return $this->error('失败');
        }
    }
    public function qu($collect_id)
    {
       $res =  Db::table('collect')->where('collect_id',$collect_id)->delete();
       if($res)
        {
            return $this->success('取消成功','me/shou');
        }
        else
        {
            return $this->error('失败');
        }
    }
}